package com.haoshuang.zhouzhoubang.widget.camera;

import com.luck.picture.lib.config.SelectorConfig;

import java.util.LinkedList;

public class SimpleCameraProviders {

    private final LinkedList<SimpleCameraConfig> selectionConfigsQueue = new LinkedList<>();

    public void addSelectorConfigQueue(SimpleCameraConfig config) {
        selectionConfigsQueue.add(config);
    }

    public SimpleCameraConfig getSelectorConfig() {
        return selectionConfigsQueue.size() > 0 ? selectionConfigsQueue.getLast() : new SimpleCameraConfig();
    }

    public void destroy() {
        SimpleCameraConfig selectorConfig = getSelectorConfig();
        if (selectorConfig != null) {
            selectorConfig.destroy();
            selectionConfigsQueue.remove(selectorConfig);
        }
    }

    public void reset() {
        for (int i = 0; i < selectionConfigsQueue.size(); i++) {
            SimpleCameraConfig selectorConfig = selectionConfigsQueue.get(i);
            if (selectorConfig != null) {
                selectorConfig.destroy();
            }
        }
        selectionConfigsQueue.clear();
    }

    private static volatile SimpleCameraProviders simpleCameraProviders;

    public static SimpleCameraProviders getInstance() {
        if (simpleCameraProviders == null) {
            synchronized (SimpleCameraProviders.class) {
                if (simpleCameraProviders == null) {
                    simpleCameraProviders = new SimpleCameraProviders();
                }
            }
        }
        return simpleCameraProviders;
    }

}
